<?php
//Результат вложенный масив в виде дерева категорий
class IdCategoryTree {
    public $categories = array();
    public $result = array();

    public function __construct()
    {
        $this->categories = CatalogCategory::getAllCategory();
    }

    public function getIdTreeCategory($parentId = null)
    {
        foreach($this->categories as $category)
        {
                if ($category['parent_id'] == $parentId)
                {
                        $this->result[] = $category['id'];
                        $this->getIdTreeCategory($category['id']);
                }
        }
        return $this->result;
    }
}